package thesis.ramstorage.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import thesis.ramstorage.application.SystemConfiguration;

public class Util {
//	 Read properties file.
	
	public static SystemConfiguration loadConfig(){
		
		SystemConfiguration config = new SystemConfiguration();
		
		Properties prop = new Properties();
	    try {
	        prop.load(new FileInputStream("./resources/schema1.properties"));
	        config.setNumberOfPhysicalNode(Integer.parseInt(prop.getProperty("number_of_node")));
	        config.setProtocol(prop.getProperty("protocol"));
	        config.setSimulatedMode(prop.getProperty("simulated_mode"));
	        config.setSimulatedData(Long.parseLong(prop.getProperty("simulated_data")));
	        config.setInitialData(Integer.parseInt(prop.getProperty("initial_data")));
	        config.setMinCapacity(Integer.parseInt(prop.getProperty("node_capacity_min")));
	        config.setMaxCapacity(Integer.parseInt(prop.getProperty("node_capacity_max")));
	        config.setHashKeySize(Integer.parseInt(prop.getProperty("hash_key_size")));
	        config.setScenario(prop.getProperty("scenario"));
	        config.setOverloadClaim(Double.parseDouble(prop.getProperty("overload_claim")));
                config.setSubstituteNodes(Integer.parseInt(prop.getProperty("number_of_subsitute_node")));
	    }
	    catch (IOException e) {
	    }
	    return config;
	}
	
	public static  boolean isEmptyString(String str){
		return (str == null || str.trim().equals(""));
	}
    
}
